package com.example.secondhandmall.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.secondhandmall.R;
import com.example.secondhandmall.adapter.CollectedAdapter;
import com.example.secondhandmall.adapter.GoodsAdapter;
import com.example.secondhandmall.adapter.SearchAdapter;
import com.example.secondhandmall.entity.GoodsEntity;
import com.example.secondhandmall.entity.SearchGoodsEntity;
import com.scwang.smart.refresh.layout.api.RefreshLayout;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class SearchSuccessActivity extends BaseActivity {

    private RecyclerView recyclerView;
    private SearchAdapter searchAdapter;
    private List<SearchGoodsEntity> datas;
    private ImageView ivReturn;
    private TextView tvSearchWord;
    private HashMap success;

    @Override
    protected int initLayout() {
        return R.layout.activity_search_success;
    }

    @Override
    protected void initView() {
        recyclerView = findViewById(R.id.recyclerView);
        ivReturn = findViewById(R.id.iv_return);
        tvSearchWord = findViewById(R.id.tv_search_word);
    }

    @Override
    protected void initData() {
        ivReturn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        //网格布局管理器
        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 2);
        recyclerView.setLayoutManager(gridLayoutManager);

        searchAdapter = new SearchAdapter(this);
        recyclerView.setAdapter(searchAdapter);

        searchAdapter.setOnItemClickListener(new SearchAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int id) {
                navigateTo(DetailActivity.class, "detail", id);
            }
        });

        //不用请求数据，数据由HomeFragment传进来
        success = (HashMap) getIntent().getSerializableExtra("success");
        datas = (List<SearchGoodsEntity>) success.get("list");
        searchAdapter.setDatas(datas);
        searchAdapter.notifyDataSetChanged();
        tvSearchWord.setText((String) success.get("searchWord"));
    }
}